<template>
  <div class="custom_page">
    <div class="content">
      <div class="toolbar">
        <div class="label">保证金总额</div>
        <div class="bondClass">{{ allMoney }}</div>
      </div>
      <!--  表格 -->
      <div class="content_table">
        <div class="table">
          <!-- <div class="tableTop">
            <span>交易记录</span>
          </div> -->
          <el-table
            v-loading="tableLoading"
            :data="tableData"
            border
            :header-cell-style="{ background: '#EEF3FF', color: '#333333' }"
            style="width: 100%"
            class="dataTable"
          >
            <el-table-column prop="bondType" label="保证金类型" />
            <el-table-column prop="activityName" label="活动名称" />
            <el-table-column prop="transactionId" label="交易流水号" />
            <el-table-column prop="bondMoney" label="保证金金额" />
            <el-table-column label="保证金状态">
              <template #default="scope">
                <span v-if="scope.row.bondState == 0">待支付</span>
                <span v-if="scope.row.bondState == 1">冻结中</span>
                <span v-if="scope.row.bondState == 2">已退回</span>
              </template>
            </el-table-column>
            <el-table-column prop="time" label="交易时间" />
          </el-table>
          <div class="fenye">
            <el-pagination
              v-model:current-page="searchForm.page"
              :page-sizes="[10, 20, 50, 100]"
              :page-size="searchForm.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              background
              :total="total"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onBeforeMount } from 'vue'
import { getAllBond } from '@/api/finance'

const tableLoading = ref(false)
const searchForm = ref({
  page: 1,
  pageSize: 10
})
const total = ref(1)
const allMoney = ref('')
const tableData = ref([])

onBeforeMount(() => {
  getAll()
})
const handleSizeChange = (val) => {
  searchForm.value.pageSize = val
  getAll()
}
const handleCurrentChange = (val) => {
  searchForm.value.page = val
  getAll()
}
// 初始化查询所有数据
const getAll = async () => {
  try {
    tableLoading.value = true
    const res = await getAllBond(searchForm.value)
    tableData.value = res.data.page.list
    total.value = res.data.page.total
    allMoney.value = res.data.total
  } finally {
    tableLoading.value = false
  }
}
</script>

<style lang="scss" scoped>
.custom_page {
  padding: 20px;
  margin-top: 20px;
  background-color: #FFFFFF;
}
.toolbar {
  display: flex;
  align-items: center;
  height: 40px;
  margin-bottom: 20px;
  .label {
    font-size: 18px;
    font-weight: bold;
  }
}
.bondClass {
  font-size: 28px;
  color: #ffae11;
  margin-left: 20px;
}
.tableTop {
  background: #d7d7d7;
  margin: 0;
  padding: 10px;
}
</style>
